﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using GDFlacTool.Common;

namespace GDFlacTool.Forms
{
    public partial class FormViewReport : Form
    {
        private readonly IList<Track> _tracks;
        private FormProgress frm;
        private Report rpt;

        public FormViewReport(IList<Track> tracks)
        {
            InitializeComponent();

            _tracks = tracks;

            Height = Properties.ReportViewerSettings.Default.FormHeight;
            Width = Properties.ReportViewerSettings.Default.FormWidth;
        }

        private void FormReport_Load(object sender, EventArgs e)
        {
            //var rpt = new Report(_tracks);

            //rpt.Run();

            //ReportViewer.Document = rpt.Document;
        }

        private void FormViewReport_FormClosing(object sender, FormClosingEventArgs e)
        {
            Properties.ReportViewerSettings.Default.FormHeight = Height;
            Properties.ReportViewerSettings.Default.FormWidth = Width;

            Properties.ReportViewerSettings.Default.Save();
        }

        private void FormViewReport_Shown(object sender, EventArgs e)
        {
            frm = new FormProgress();

            

            bgwCreateReport.RunWorkerAsync();frm.ShowDialog(this);
        }

        private void bgwCreateReport_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            rpt = new Report(_tracks);
            rpt.Run();
        }

        private void bgwCreateReport_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
        {
            ReportViewer.Document = rpt.Document;

            frm.Close();
        }
    }
}
